package com.mineplatform.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mineplatform.dao.M_MineDao;
import com.mineplatform.dao.M_ReplyDao;
import com.mineplatform.domain.M_Mine;
import com.mineplatform.domain.M_Reply;
import com.mineplatform.domain.M_User;
import com.mineplatform.domain.MineReplyShow;
import com.mineplatform.domain.ReplyContainsUserInfo;
import com.mineplatform.exception.MineIdNullOrEmptyException;
import com.mineplatform.exception.MineNotExistException;
import com.mineplatform.exception.RecordNotExistException;
import com.mineplatform.exception.UserNotExistException;
import com.mineplatform.iservice.IM_ReplyService;

@Service
public class M_ReplyService implements IM_ReplyService {

	private M_ReplyDao _m_replydao;
	private final M_MineDao _m_minedao;

	@Autowired
	public M_ReplyService(M_ReplyDao m_replydao, M_MineDao m_minedao) {
		this._m_replydao = m_replydao;
		this._m_minedao = m_minedao;
	}

//	@Transactional(propagation = Propagation.REQUIRED)
//	@Override
//	public List<MineReplyShow> findAll(){		
//		return this._m_replydao.findAll();		
//	}
	
	
	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public List<ReplyContainsUserInfo> findByMineId(String mineid) throws MineIdNullOrEmptyException, MineNotExistException {
		// TODO Auto-generated method stub

		if ((mineid == null) || (mineid.equals(""))) {

			throw new MineIdNullOrEmptyException();
		}

		M_Mine mine = this._m_minedao.findById(mineid);

		if (mine == null) {
			throw new MineNotExistException();
		}

		return this._m_replydao.findByMineId(mineid);
	}

	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public void delete(String replyid) throws RecordNotExistException {
		// TODO Auto-generated method stub

		M_Reply reply = this._m_replydao.findById(replyid);
		if (reply == null) {
             throw new RecordNotExistException();
		}
		this._m_replydao.remove(replyid);
	}
}
